<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Vue-router</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
</head>

<body>
    <div id="app">
        <div class="nav">
            <!-- 使用 router-link 组件来导航. -->
            <!-- 通过传入 `to` 属性指定链接. -->
            <!-- <router-link> 默认会被渲染成一个 `<a>` 标签 -->
            <router-link to="/vue">简易VUE</router-link>
            <router-link to="/es6">趣味ES6</router-link>
            <router-link to="/career">人在职场</router-link>
        </div>
        <div>
            <!-- 路由匹配到的组件将渲染在这里 -->
            <router-view></router-view>
        </div>


    </div>
    <script>
        // 1.定义路由组件
        const vueComponent = {
            template: '<div>这里是简易Vue </div>'
        }
        const es6Component = {
            template: '<div>这里是趣味ES6 </div>'
        }
        const careerComponent = {
            template: '<div>这里是人在职场 </div>'
        }
        // 2.定义路由，并创建router实例
        const router = new VueRouter({
            routes: [{
                    path: '/vue',
                    component: vueComponent
                },
                {
                    path: '/es6',
                    component: es6Component
                },
                {
                    path: '/career',
                    component: careerComponent
                }
            ]
        })
        // 3.创建和挂载路由
        var app = new Vue({
            el: '#app',
            router
        })
    </script>
</body>

</html>